package com.mengniu.commerce.sync.api.factory;


import com.mengniu.commerce.sync.api.RemotePointService;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.PointsIncreaseModel;
import com.mengniu.commerce.sync.api.domain.PointsReduceModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 新增积分降级处理
 *
 * @author yz_sm
 */
@Component
public class RemotePointFallbackFactory implements FallbackFactory<RemotePointService>
{
    private static final Logger log = LoggerFactory.getLogger(RemotePointFallbackFactory.class);

    @Override
    public RemotePointService create(Throwable throwable)
    {
        log.error("数据同步服务--积分--调用失败:{}", throwable.getMessage());
        return new RemotePointService()
        {
            @Override
            public MnResult increasePoint(PointsIncreaseModel pointsIncreaseModel, String source)
            {
                return new MnResult("","新增积分失败:" + throwable.getMessage(),false);
            }

            @Override
            public MnResult decreasePoint(PointsReduceModel pointsReduceModel, String source) {
                return new MnResult("","扣减积分失败:" + throwable.getMessage(),false);
            }

        };
    }
}
